home *** CD-ROM | disk | FTP | other *** search
- /* dumb vulnerable program example, that uses function pointers */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <string.h>
-
- #define ERROR -1
- #define BUFSIZE 64
-
- void goodfunc()
- {
- printf("I'm the real goodfunc(). I have been called.\n");
- return;
- }
-
- int main(int argc, char **argv)
- {
- static char buf[BUFSIZE];
- static void (*funcptr)();
-
- if (argc <= 2)
- {
- fprintf(stderr, "Usage: %s <string1> <string2>\n", argv[0]);
- exit(ERROR);
- }
-
- funcptr = &goodfunc;
- memset(buf, 0, BUFSIZE);
-
- printf("argv[1] = %p\n", argv[1]);
- printf("buf = %p\n\n", buf);
-
- printf("before: funcptr = %p\n", funcptr);
- strncpy(buf, argv[2], strlen(argv[2]));
- printf("after: funcptr = %p\n\n", funcptr);
-
- (*funcptr)();
- return 0;
- }
-